package com.svm.operators;

import java.io.File;

import com.svm.bean.Image;
import com.svm.bean.Parameter;
import com.svm.bean.SvmClass;
import com.svm.util.SvmClassUtils;

public class Classification {

	private Parameter param;

	public Classification(Parameter param) {
		this.param = param;
	}

	public void classify() {

		SvmClass svmClass = new SvmClass();
		svmClass.setCompAlgorithm(param.getCompAlgorithm());
		svmClass.setFeatDimenX(param.getFeatDimenX());
		svmClass.setFeatDimenY(param.getFeatDimenY());
		svmClass.setName(param.getClassName());

		if (param.getImagesFile().isDirectory()) {

			svmClass.setAbsolutePath(param.getImagesFile().getAbsolutePath());

			for (File file : param.getImagesFile().listFiles()) {
				Parameter pa = param;
				pa.setImagesFile(file);

				FeatureExtraction extraction = new FeatureExtraction(pa);
				Image image = extraction.extract();
				svmClass.getImages().add(image);
			}
		}

		SvmClassUtils.saveSvmClass(svmClass);

	}

}
